#pragma GCC optimize(2)
#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#include <stack>
#include <bitset>
#define F first
#define S second
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=1e6+10;
int f[N];
int c[N];
int ne[N],h[N],siz[N];
int tail[N];
int ans;
void merge(int c1,int c2)
{
	for(int i=h[c1];i;i=ne[i])
	{
		ans-= (c[i-1]==c2) + (c[i+1]==c2);
	}
	for(int i=h[c1];i;i=ne[i])
	{
		c[i]=c2;
	}
	
	siz[c2]+=siz[c1];
	ne[tail[c1]]=h[c2];
	h[c2]=h[c1];
	
	tail[c1]=0;
	siz[c1]=0;
	h[c1]=0;
}
void solve()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		f[c[i]]=c[i];
		if(c[i]!=c[i-1]) ans++;
		if(h[c[i]]==0)
		{
			tail[c[i]]=i;
		}
		siz[c[i]]++;
	    ne[i]=h[c[i]];
	    h[c[i]]=i;
	}
	while(m--)
	{
		int op;
		cin>>op;
		if(op==2)
		{
			cout<<ans<<endl;
		}
		else
		{
			int x,y;
			cin>>x>>y;
			if(x==y) continue;
			if(siz[f[x]]>siz[f[y]]) swap(f[x],f[y]);
			if(siz[f[x]]==0) continue;
			merge(f[x],f[y]);
		} 
	}
}
int main()
{
	IOS;
	int T=1;
//	cin>>T;

	while(T--)
	{
		solve();
	}

	return 0;
}

